#ifndef CARESIZE_H
#define CARESIZE_H
#include <QImage>
#include "sobelfilter.h"

class Caresize
{
    //ATRIBUTES
    int seamsProcessed; //Number of seams from the original image already in the SeamMap
    int seamsAdded; //Number of seams added to the original image and SeamMap (negatives)
    int fractionAdd;    //Default is 50% of original seams used when adding new seams
    int maxSeams;   //Max number of semas that can be processed
    int horv;   //horizontal or vertical?
    int minSeams;
    int originalHeight;
    int originalWidth;

    QImage image;   //The original image which can become larger
    QImage workGray;    //The grayscale of the original image. It only goes smaller. used for processing.
    int **energy;   //The energy used for processing seams - we use SOBEL
    int **m;    //Optimal Path matrix
    int ** seamMap; //Seam Map - Can be horizontal or vertical.

    //METHODS
    //Horizontal
    int ** horizontalM();   //Compute Optimal Path matrix
    int *horizontalBacktrack(); //Backtrack the Optimal Path matrix to find seam
    int *horizontalSeam();  //Returns seam computed
    void horizontalPaint(int*); //Used for painting and testing purposes
    void horizontalUpdateEnergy(int *); //Optimized function to update the energy matrix
    void updateHSeamMap(int *seam);
    void addHSeamMap(int *seam);
    void addHSeamImage(int *seam);
    int *getHSeam(int);

    //Vertical
    int ** verticalM();   //Compute Optimal Path matrix
    int *verticalBacktrack(); //Backtrack the Optimal Path matrix to find seam
    int *verticalSeam();  //Returns seam computed
    void verticalPaint(int*); //Used for painting and testing purposes
    void verticalUpdateEnergy(int *); //Optimized function to update the energy matrix
    void updateVSeamMap(int *seam);
    void addVSeamMap(int *seam);
    void addVSeamImage(int *seam);
    int *getVSeam(int);

    //General
    int ** createMatrix(int, int);
    void destroyMatrix(int **,int);
    void sobel(); //Arun's Sobel
    void transformGray();   //Transform to gray the image
    void assertEnergy();    //Testing the optimized energy and the energy obtained from sobel
    void assertSeamMap();   //Testing the SeamMap

public:
    Caresize();
    Caresize(QImage image);
    ~Caresize();

    //Horizontal
    void horizontalProcess();
    void horizontalProcessN(int);
    void horizontalAddN(int);
    int maxResizeH();
    int minResizeH();
    void horizontalInit();

    //Vertical
    void verticalProcess();
    void verticalProcessN(int);
    void verticalAddN(int);
    void verticalInit();
    int maxResizeV();
    int minResizeV();

    //Vertical
    QImage getImage();
    QImage resizeImageH(int);
    QImage resizeImageV(int);
};

#endif // CARESIZE_H
